﻿Imports System.Data.SqlClient
Imports System.Configuration

Public Class Cliente
    Implements ICliente

    Public Function InformacionFinancieraxDni(ByVal dniCliente As String) As DataSet Implements ICliente.InformacionFinancieraxDni

        Dim result As New DataSet()

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("Sql2008").ConnectionString.ToString())
            cn.Open()

            Using cmd As New SqlCommand()
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "dbo.usp_sel_inf_financiera"
                cmd.Connection = cn
                cmd.Parameters.AddWithValue("@dni", dniCliente)

                Dim da As New SqlDataAdapter(cmd)
                da.Fill(result)

                result.Tables(0).TableName = "dtCuentas"
                result.Tables(1).TableName = "dtCreditos"
            End Using
            cn.Close()

        End Using

        Return result
    End Function

    Public Function ListaClientexFiltro(ByVal nombre As String, ByVal apellido As String, ByVal numCuenta As String) As Object Implements ICliente.ListaClientexFiltro
        Dim result As New DataTable("dtClientes")

        Dim tabla As New DataTable("dtClientes")
        tabla.Columns.Add("Nombre")
        tabla.Columns.Add("Apellidos")
        tabla.Columns.Add("NumeroCuenta")

        Dim fila1 As DataRow = tabla.NewRow()

        fila1("Nombre") = "Luis"
        fila1("Apellidos") = "Muñoz"
        fila1("NumeroCuenta") = "015464654854646"

        Dim fila2 As DataRow = tabla.NewRow()

        fila2("Nombre") = "Juan"
        fila2("Apellidos") = "Perez"
        fila2("NumeroCuenta") = "0005646456455"

        tabla.Rows.Add(fila1)
        tabla.Rows.Add(fila2)

        'Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("SQL2008").ConnectionString)
        '    cn.Open()
        '    Using cmd As New SqlCommand("usp_listaClientes", cn)
        '        cmd.CommandType = CommandType.StoredProcedure
        '        Dim da As New SqlDataAdapter(cmd)
        '        da.Fill(result)
        '    End Using
        '    cn.Close()
        'End Using
        Dim ds As New DataSet
        ds.Tables.Add(tabla)
        Return ds
    End Function

    Public Function ClientexDni(ByVal dni As String) As DataSet Implements ICliente.ClientexDni


        Dim result As New DataSet()

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings("Sql2008").ConnectionString.ToString())
            cn.Open()

            Using cmd As New SqlCommand()
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "dbo.usp_sel_clientexdni"
                cmd.Connection = cn
                cmd.Parameters.AddWithValue("@dni", dni)

                Dim da As New SqlDataAdapter(cmd)
                da.Fill(result)

                result.Tables(0).TableName = "dtCliente"

            End Using
            cn.Close()

        End Using

        Return result

    End Function
End Class
